/********************************************************/
/* Texture by George Chew        */
/* For use in GeorgeLib        */
/* Created Apr 2013         */
/*              */
/* Version 0001          */
/********************************************************/

#ifndef __TEXTURE_H__
#define __TEXTURE_H__

#include "stdafx.h"
#include "Logger.h"
#include "vec2.h"
#include "vec3.h"
#include "Node.h"
#include <vector>

namespace GeorgeLib
{

	class DLLEXPORT Texture
	{
	protected:
		GLubyte* imageData;  // Image data (up to 32 bits)
		GLuint bpp;   // Image color depth in bits/pixel
		GLuint width;   // Image width
		GLuint height;   // Image height

	public:
		GLuint id;    // Texture ID used to select a texture

		Texture(void);
		~Texture(void);

		bool LoadTGA(char * filename, bool mipmap = false);
		bool LoadTGAc(char * filename, bool mipmap = false);

		bool LoadPNG(char *filename, bool mipmap = false);

		void Draw(vec3 vertices[4], vec2 texcoords[4] = NULL, vec3 normal = vec3(0, 0, 0));
		void Draw(float vertices[12], float texcoords[8] = NULL, float normal[3] = NULL);

		void drop(void);
	};

	class Texture2D : private Texture
	{
	public:

		SYNTHESIZE(vec2, size, Size);

		Texture2D(void) : size(vec2(1, 1)) {};
		Texture2D(const char *filename, vec2 size = vec2(0, 0));

		void LoadTGA(const char *filename);
		virtual void Draw(void);
	};

#ifndef _MULTI_TEX_ARB_FUNCS_DEFINED
#define _MULTI_TEX_ARB_FUNCS_DEFINED

	// ARB multi-texturing function pointers
	static PFNGLACTIVETEXTUREARBPROC _glActiveTextureARB;
	static PFNGLMULTITEXCOORD2FARBPROC _glMultiTexCoord2fARB;

#endif

	class MultiTexture
	{
	public:
		vector<Texture> texArray;  // Array of textures

		MultiTexture(void);
		~MultiTexture(void);

		Texture  getTexture(uint id);
		void  setTexture(uint id, Texture texture);
		uint  addTexture(Texture texture);
		bool  cutTexture(Texture texture);
		bool  cutTexture(uint id);

		void  Draw(vec3 vertices[4], vec2 texcoords[4] = NULL, vec3 normal = vec3(0, 0, 0));
		void  Draw(float vertices[12], float texcoords[8] = NULL, float normal[3] = NULL);

		void  drop(void);

		friend bool InitMultiTexturing(void);

		friend void glActiveTextureARB(GLenum texture);

		friend void glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t);
	};

} // namespace GeorgeLib 

#endif // __TEXTURE_H__ //